package com.qys.livesMall.file.server.upload.service.impl.oss.proper;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import jakarta.annotation.PostConstruct;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * Created by IntelliJ IDEA.
 * User: dp
 * Date: 2023/05/19
 * Time: 10:10
 * DESCRIPTION: oss配置
 */
@Data
@Component
public class OssStorageProperties {
    @Value("${upload.oss}")
    private boolean ossUp ;
    @Value("${upload.aliyun.oss.endpoint}")
    private String aliendpoint = "";
    @Value("${upload.aliyun.oss.accesskeyid}")
    private String aliaccesskeyid = "";
    @Value("${upload.aliyun.oss.accesskeysecret}")
    private String aliaccesskeysecret = "";
    @Value("${upload.aliyun.oss.bucketName}")
    private String alibucketname = "";
    @Value("${upload.aliyun.oss.maxSize}")
    private Long maxSize;

    @Value("${upload.aliyun.oss.baseUrl}")
    private String baseUrl;

    public static OSS oss;
    public static String ossUrl;
    public static Long fileMaxSize;

    @PostConstruct
    public void init() {
        oss = new OSSClientBuilder().build(
                this.aliendpoint,
                this.aliaccesskeyid,
                this.aliaccesskeysecret
        );
        ossUrl = this.alibucketname;
        fileMaxSize = this.maxSize;
    }
}
